package xin.mashibo.pattern.abstractfactory;

import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;

/**
 * @author MaShibo
 * 日期 :  2019/1/23
 */
public abstract class Page {

    protected String title;

    protected String author;

    protected ArrayList<Item> content = new ArrayList<>();

    public Page(String title, String author) {
        this.title = title;
        this.author = author;
    }

    public void add(Item item) {
        content.add(item);
    }

    public void output() {
        String fileName = title + ".html";
        try {
            Writer writer = new FileWriter(fileName);
            try {
                writer.write(this.makeHTML());
                writer.close();
                System.out.println(fileName + "编写完成。");
            } finally {
                writer.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    public abstract String makeHTML();

}
